package com.gxc.core.validate.code;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.awt.image.BufferedImage;
import java.time.LocalDateTime;

/**
 * 验证码.
 *
 * @author GongXincheng
 * @since 2019-10-16 16:09
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ImageCode {

    private BufferedImage image;

    private String code;

    private LocalDateTime expireTime;


    /**
     * @param expire 秒
     */
    public ImageCode(BufferedImage image, String code, long expire) {
        this.image = image;
        this.code = code;
        this.expireTime = LocalDateTime.now().plusSeconds(expire);
    }

    public boolean isExpried() {
        return LocalDateTime.now().isAfter(this.getExpireTime());
    }
}
